package com.liliang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liliang.entity.MaterialPage;
import com.liliang.entity.Stock;
import com.liliang.mapper.StockMapper;
import com.liliang.service.IStockService;
import com.liliang.utils.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liliang
 * @since 2021-11-04
 */
@Service
public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements IStockService {

    @Autowired
    StockMapper sm;

    @Override
    public boolean insertStock(Stock stock, String cgbzsj) {
        stock.setStockNum(RandomUtil.getliushuihao("cgjh"));
        return this.save(stock);
    }

    @Override
    public MaterialPage findStockPage(int page, Integer rows, Stock stock, String materialName, String status) {
        //创建分页对象
        MaterialPage materialPage=new MaterialPage();
        //得到模糊查询的数值
        String stockName = stock.getStockName();
        if (stockName!=null){
            stockName="%"+stockName+"%";
        }
        if (materialName!=null){
            materialName="%"+materialName+"%";
        }
        System.out.println(stock.getStockType());
        //模糊查询总行数
        materialPage.setMax(sm.findStockCountLike(stockName,materialName,stock.getStockType(),status));
        //模糊分页查询
        materialPage.setMaterial(sm.findStockPage(page,rows,stockName,materialName,stock.getStockType(),status));
        return materialPage;
    }

    @Override
    public MaterialPage selectStockByStatus(int i, Integer rows) {
        //创建分页对象
        MaterialPage materialPage=new MaterialPage();
        materialPage.setMax(sm.selectStockByStatuscount());
        materialPage.setMaterial(sm.selectStockByStatus(i,rows));
        return materialPage;
    }

    @Override
    public MaterialPage selectStockByStatus2(int i, Integer rows, String zt) {
        MaterialPage materialPage=new MaterialPage();
        materialPage.setMax(sm.selectStockByStatuscount2(zt));
        materialPage.setMaterial(sm.selectStockByStatus2(i,rows,zt));
        return materialPage;
    }
}
